package main

import (
	"fmt"
	"time"
)

type Paper struct {
	TeacherId int
	PaperId   int
}

func main() {
	start := time.Now()
	var (
		totalPaper  = 1200 //总试卷数
		teacherNum  = 6    //老师数
		paperChan   = make(chan *Paper, 400)
		classNum    = 10 //班级数
		classPerNum = 40 //每个班级人数
		complete    = make(chan bool)
	)

	for i := 0; i < teacherNum; i++ {
		go TeacherSend(i, totalPaper/teacherNum, paperChan)
	}

	go StudentRecv(classNum, classPerNum, paperChan, complete)

	<-complete
	d := time.Since(start).Seconds()
	fmt.Println("总耗时 = ", d)
}

func TeacherSend(teacherId int, nums int, paper chan *Paper) {
	for i := 0; i < nums; i++ {
		time.Sleep(time.Second)
		paper <- &Paper{
			TeacherId: teacherId,
			PaperId:   i,
		}
	}
}

func StudentRecv(classNum int, classPerNum int, paper chan *Paper, complete chan bool) {
	for class := 0; class < classNum; class++ {
		for i := 0; i < classPerNum; i++ {
			paperInfo := <-paper
			fmt.Printf("班级:%d,学生id:%d,获得的试卷信息->教师id:%d,试卷id:%d\n", class, i, paperInfo.TeacherId, paperInfo.PaperId)
		}
	}
	complete <- true
}
